import 'package:FlutterStudy/demo/mine/MineController.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:image_picker/image_picker.dart';
import 'Timage.dart';

class BgDetail extends StatefulWidget {
  String originPath;
  BgDetail({required this.originPath});

  @override
  _BgDetailState createState() {
    return _BgDetailState();
  }
}

class _BgDetailState extends State<BgDetail> {
  @override
  void initState() {
    super.initState();
    print(  Get.find<MineController>().bg);
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Stack(
        children: [
          TImage(Get.find<MineController>().bg, double.infinity, double.infinity,BoxFit.fitWidth),
          Align(child: ElevatedButton(onPressed: _selectPhoto, child: const Text("更换背景")),
            alignment: Alignment.center.add(Alignment(0, 0.4))
          )

        ],
      ),
    );
  }

  final ImagePicker _picker = ImagePicker();

  Future<void> _selectPhoto() async {
    final XFile? image = await _picker.pickImage(source: ImageSource.gallery);

    print(image?.path);
    Navigator.of(context).pop(image?.path);
  }
}